package com.example.demo.tests;

import com.example.demo.common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public class ArticleManagePage extends Utils {

    public static String url = "http://82.157.143.27:8081/index.html";

    public ArticleManagePage() {
        super(url);
    }

    //发布帖子
    public void CreatArticle() throws InterruptedException {

        driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")).click();
        driver.findElement(By.cssSelector("#article_post_title")).sendKeys("1自动化测试");
        Thread.sleep(2000);
        WebElement element = driver.findElement(By.cssSelector("#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre"));
        Actions actions = new Actions(driver);
        actions.doubleClick(element).perform();
        actions.moveToElement(element).sendKeys("测试1").perform();

        Thread.sleep(3000);
      driver.findElement(By.cssSelector("#article_post_submit")).click();
    }

    //删除帖子
    public void DeleteArticle(){
        driver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).click();
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div:nth-child(1) > div.col-9.card.card-lg > div.card-footer.bg-transparent.mt-auto.justify-content-end > div > div:nth-child(3) > div > a")).click();

        //确认删除
        driver.findElement(By.cssSelector("#details_artile_delete")).click();

    }

    //点赞帖子
    public void GoodArticle(){
        driver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).click();
        driver.findElement(By.cssSelector("#details_btn_like_count")).click();
    }
}
